package com.qd.panda.stroke;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.panda.domain.entity.stroke.*;
import com.qd.common.sys.annotation.DataScope;
import com.qd.panda.service.stroke.UserStrokeHistoryService;
import com.qd.panda.service.stroke.order.UserStrokeOrderRefundService;
import com.qd.panda.service.stroke.order.UserStrokeOrderService;
import com.qd.panda.service.stroke.UserStrokeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * WEB_用户行程
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/sys/userStroke/")
@Slf4j
public class UserStrokeController {
    private final UserStrokeHistoryService userStrokeHistoryService;
    private final UserStrokeService userStrokeService;
    private final UserStrokeOrderService userStrokeOrderService;

    private final UserStrokeOrderRefundService userStrokeOrderRefundService;

    /**
     * 历史行程列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "historyPage")
    @DataScope(orgAlias = "us", orgIdAlias = "park_id")
    public IPage<WebUserStrokeDTO> historyPage(UserStrokeHistoryDTO dto) {
        return userStrokeHistoryService.webPage(PageUtil.buildPage(dto), dto);
    }

    /**
     * 进行中行程列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "processPage")
    @DataScope(orgAlias = "us", orgIdAlias = "park_id")
    public IPage<WebUserStrokeDTO> processPage(UserStrokeDTO dto) {
        return userStrokeService.webPage(PageUtil.buildPage(dto), dto);
    }

    /**
     * 根据行程查询订单列表
     *
     * @param sid 行程ID
     * @return 列表信息
     */
    @GetMapping(value = "getOrderListBySid")
    public List<UserStrokeOrderDTO> getOrderListBySid(@Validated @NotBlank(message = "行程ID不能为空") String sid) {
        return userStrokeOrderService.getListBySid(sid);
    }

    /**
     * 根据订单ID查询退款列表
     *
     * @param orderId 订单ID
     * @return 列表信息
     */
    @GetMapping(value = "getOrderRefundListByOrderId")
    public List<UserStrokeOrderRefundDTO> getOrderRefundListByOrderId(@Validated @NotBlank(message = "订单ID不能为空") String orderId,Integer flag) {
        return userStrokeOrderRefundService.getOrderRefundListByOrderId(orderId,flag);
    }
}